package dj;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AudycjaList extends HttpServlet  { 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  String driver = "org.h2.Driver";
	try {Class.forName(driver).newInstance();	} catch (InstantiationException e1) {		e1.printStackTrace();	} catch (IllegalAccessException e1) {				e1.printStackTrace();	} catch (ClassNotFoundException e1) {				e1.printStackTrace();	}
	Connection con=null;
	ResultSet rst=null;
	Statement stmt=null;
	try{		con=DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
		stmt=con.createStatement();
	}
	catch(Exception e){
		System.out.println(e.getMessage());
	}
		try {
			rst=stmt.executeQuery("select * from audycje");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		response.setContentType("text/html");
		PrintWriter writer = response.getWriter();		
		try {
			writer.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'	'http://www.w3.org/TR/html4/strict.dtd'>");
			writer.write("<html><body><center>");
			writer.write("<h2>Audycje:</h2>");
			writer.write("<table border=1 cellspacing=0 cellpadding=0>");
writer.write("<td><b>ID</b></td><td><b>Nazwa</b></td><td><b>Godzina</b></td><td><b>P</b></td><td><b>W</b></td><td><b>S</b></td><td><b>C</b></td><td><b>P</b></td><td><b>S</b></td><td><b>N</b></td>");			
			while(rst.next()){
			writer.write("<tr>");
			writer.write("<td>");writer.write(rst.getString("id"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("nazwa"));writer.write("</td>");
		//	writer.write("<td>");writer.write(rst.getString("opis"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("godzina")+":00");writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("poniedzialek"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("wtorek"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("sroda"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("czwartek"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("piatek"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("sobota"));writer.write("</td>");
			writer.write("<td>");writer.write(rst.getString("niedziela"));writer.write("</td>");
			writer.write("</tr><br>");
			}
			writer.write("</table>");
			writer.write("<a href=index.jsp>Powrot</a>");
			writer.write("				<center><body><html>");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}